package cn.slipi.core.plugin.pre;

import cn.slipi.common.constants.Constants;
import cn.slipi.common.entity.RequestLog;
import cn.slipi.common.enums.PluginDetailEnum;
import cn.slipi.core.plugin.IPlugin;
import cn.slipi.core.plugin.IPluginChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * RequestPlugin
 */
public class RequestPlugin implements IPlugin {

    private static final Logger LOGGER = LoggerFactory.getLogger(RequestPlugin.class);

    @Override
    public Mono<Void> execute(ServerWebExchange exchange, IPluginChain chain) {
        RequestLog requestLog = (RequestLog) exchange.getAttributes().get(Constants.REQUEST_LOG);
        requestLog.setRequest("ok");
        exchange.getAttributes().put(Constants.REQUEST_LOG, requestLog);
        return chain.execute(exchange);
    }

    @Override
    public String getPluginPhase() {
        return PluginDetailEnum.REQUEST.getPhase();
    }

    @Override
    public int getCode() {
        return PluginDetailEnum.REQUEST.getCode();
    }

    @Override
    public String getName() {
        return PluginDetailEnum.REQUEST.getName();
    }
}
